home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / util / misc / ReportPlus.lha / reportplus / source / f12.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-25  |  15.5 KB  |  488 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/gadgetclass.h>
  5. #include <workbench/icon.h>
  6. #include <workbench/workbench.h>
  7. #include <dos/dosextens.h>
  8.  
  9. #include "rp.h" // before icon protos
  10.  
  11. #include <clib/alib_protos.h>
  12. #include <clib/exec_protos.h>
  13. #include <clib/intuition_protos.h>
  14. #include <clib/icon_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <pragmas/icon_pragmas.h>
  17. #include <reaction/reaction.h>
  18.  
  19. #include <gadgets/chooser.h>
  20. #include <pragmas/chooser_pragmas.h>
  21. #include <gadgets/string.h>
  22. #include <pragmas/string_pragmas.h>
  23. #include <gadgets/checkbox.h>
  24. #include <pragmas/checkbox_pragmas.h>
  25. #include <gadgets/layout.h>
  26. #include <pragmas/layout_pragmas.h>
  27. #include <gadgets/button.h>
  28. #include <pragmas/button_pragmas.h>
  29. #include <images/label.h>
  30. #include <pragmas/layout_pragmas.h>
  31. #include <proto/label.h>
  32. #include <classes/window.h>
  33. #include <pragmas/window_pragmas.h>
  34.  
  35. #include <stdlib.h>
  36. #include <string.h>
  37.  
  38. /* Notes regarding this module:
  39.     1) the right window border is not respected when running in PAL mode.
  40.        The cause of this has not been determined, it may possibly be due
  41.        to a bug in ReAction? Current workaround is not to allow use of
  42.        this module in PAL mode.
  43.     2) the hook routine did not work, again the cause of this has
  44.        not been determined. Current workaround is not to use any hooks.
  45.        The desire is to support Escape as a shortcut for the `Menu' button,
  46.        and P as a shortcut for the `Pathname(s)' string gadget.
  47.    If anyone knows why these problems occur, please contact us. */
  48.  
  49. AGLOBAL struct Object*     object            = NULL;
  50. AGLOBAL ULONG              app, signal;
  51. AGLOBAL ABOOL              quit              = FALSE;
  52. AGLOBAL struct Gadget*     gadgets[GIDS_12 + 1];
  53. MODULE  ABOOL              stop;
  54.  
  55. // from rp.c
  56. IMPORT ABOOL               fillwindows;
  57. IMPORT SBYTE               page;
  58. IMPORT TEXT                asldir[VLONGFIELD + 1];
  59. IMPORT ULONG               fillcolour;
  60. IMPORT struct Gadget      *BU99_Left,
  61.                           *BU99_Right,
  62.                           *PrevGadPtr;
  63. IMPORT struct Window*      MainWindowPtr;
  64. IMPORT struct Screen*      ScreenPtr;
  65. IMPORT struct SharedStruct shared;
  66. IMPORT struct Library*    *ButtonBase,
  67.                           *CheckBoxBase,
  68.                           *ChooserBase,
  69.                           *IconBase,
  70.                           *LabelBase,
  71.                           *LayoutBase,
  72.                           *StringBase,
  73.                           *WindowBase;
  74. IMPORT struct Menu*        MenuPtr;
  75. IMPORT ABOOL               done;
  76. IMPORT TEXT                aslresult[VLONGFIELD + 1];
  77.  
  78. AGLOBAL struct IconStruct  icon =
  79. {   TRUE, FALSE,
  80.     WBTOOL - 1
  81. };
  82.  
  83. MODULE STRPTR IconOptions[7 + 1] =
  84. {   "Disk",
  85.     "Drawer",
  86.     "Tool",
  87.     "Project",
  88.     "Trashcan",
  89.     "Device",
  90.     "Kickstart",
  91.     "AppIcon"
  92. };
  93. /* icon.type is 1 less than the actual value used by the system (those
  94. start from 1, ours start from 0). */
  95.  
  96. AGLOBAL void icon1(void)
  97. {   struct MsgPort*     AppPort;
  98.     ULONG               i;
  99.     struct List         ChooserList;
  100.     struct ChooserNode *ChooserNodePtr[7 + 1];
  101.  
  102.     shared.pathname[0] = 0;
  103.  
  104.     NewList(&ChooserList);
  105.     for (i = 0; i <= 7; i++)
  106.     {   if (!(ChooserNodePtr[i] = (struct ChooserNode *) AllocChooserNode(CNA_Text, IconOptions[i], TAG_DONE)))
  107.         {   rq("Can't allocate chooser node!");
  108.         }
  109.         AddTail(&ChooserList, (struct Node *) ChooserNodePtr[i]);
  110.     } // automatically freed by ReAction at DisposeObject() time
  111.  
  112.     if (!(AppPort = CreateMsgPort()))
  113.     {   rq("Can't create ReAction message port!");
  114.     }
  115.     /* Create the window object. */
  116.     lockscreen();
  117.     gadtools();
  118.  
  119.     if (!(object =                NewObject(WINDOW_GetClass(), NULL,
  120.     // window
  121.     WA_PubScreen,                 ScreenPtr,
  122.     WA_ScreenTitle,               "Report+",
  123.     WA_Title,                     "Report+: Icon Processor",
  124.     WA_Activate,                  TRUE,
  125.     WA_DepthGadget,               TRUE,
  126.     WA_DragBar,                   TRUE,
  127.     WA_CloseGadget,               TRUE,
  128.     WA_SizeGadget,                TRUE,
  129.     WINDOW_AppPort,               AppPort,
  130.     WINDOW_MenuStrip,             MenuPtr,
  131.     WINDOW_Position,              WPOS_CENTERSCREEN,
  132.     WINDOW_ParentGroup,           gadgets[GID_12_LY1] =
  133.                                   NewObject(LAYOUT_GetClass(), NULL,
  134.             // root-layout
  135.             LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
  136.             LAYOUT_SpaceOuter,        TRUE,
  137.             LAYOUT_DeferLayout,       TRUE,
  138.             LAYOUT_AddChild,          gadgets[GID_12_CH1] =
  139.                                       NewObject(CHOOSER_GetClass(), NULL,
  140.                 // chooser
  141.                 GA_ID,                GID_12_CH1,
  142.                 CHOOSER_PopUp,        TRUE,
  143.                 CHOOSER_Labels,       &ChooserList,
  144.                 CHOOSER_Selected,     icon.type,
  145.                 TAG_END),
  146.             CHILD_WeightedHeight,     0,
  147.             LAYOUT_AddChild,          gadgets[GID_12_CB1] =
  148.                                       NewObject(CHECKBOX_GetClass(), NULL,
  149.                 // checkbox
  150.                 GA_ID,                GID_12_CB1,
  151.                 GA_RelVerify,         TRUE,
  152.                 GA_Text,              "_Optimize colours?",
  153.                 GA_Selected,          (BOOL) icon.optimize,
  154.                 TAG_END),
  155.             CHILD_WeightedHeight,     0,
  156.             LAYOUT_AddChild,          gadgets[GID_12_CB2] =
  157.                                       NewObject(CHECKBOX_GetClass(), NULL,
  158.                 // checkbox
  159.                 GA_ID,                GID_12_CB2,
  160.                 GA_RelVerify,         TRUE,
  161.                 GA_Text,              "Preserve p_lanar data?",
  162.                 GA_Selected,          (BOOL) icon.planar,
  163.                 TAG_END),
  164.             CHILD_WeightedHeight,     0,
  165.             LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  166.                 // layout
  167.                 LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  168.                 GA_BackFill,          NULL,
  169.                 LAYOUT_SpaceOuter,    TRUE,
  170.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  171.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  172.                 LAYOUT_BevelStyle,    BVS_FIELD,
  173.                 LAYOUT_AddImage,      NewObject(LABEL_GetClass(), NULL,
  174.                     // label
  175.                     LABEL_Text,       "Pathname(s):",
  176.                     LABEL_Justification,LJ_LEFT,
  177.                     TAG_END),
  178.                 LAYOUT_AddChild,      gadgets[GID_12_ST1] =
  179.                                       NewObject(STRING_GetClass(), NULL,
  180.                     // string        
  181.                     GA_ID,            GID_12_ST1,
  182.                     STRINGA_TextVal,  shared.pathname,
  183.                     STRINGA_MinVisible,35,
  184.                     TAG_END),
  185.                 LAYOUT_AddChild,      gadgets[GID_12_BU1] =
  186.                                       NewObject(NULL, "button.gadget",
  187.                     // button
  188.                     GA_ID,            GID_12_BU1,
  189.                     GA_RelVerify,     TRUE,
  190.                     BUTTON_AutoButton,BAG_POPFILE,
  191.                     TAG_END),
  192.                 CHILD_WeightedWidth,  0,
  193.                 TAG_END),
  194.             CHILD_WeightedHeight,     0,
  195.             LAYOUT_AddChild,          gadgets[GID_12_ST2] =
  196.                                       NewObject(STRING_GetClass(), NULL,
  197.                 // string        
  198.                 GA_ReadOnly,          TRUE,
  199.                 GA_ID,                GID_12_ST2,
  200.                 STRINGA_TextVal,      "Ready.",
  201.                 TAG_END),
  202.             CHILD_WeightedHeight,     0,
  203.             LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  204.                 // layout
  205.                 LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  206.                 GA_BackFill,          NULL,
  207.                 LAYOUT_SpaceOuter,    TRUE,
  208.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  209.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  210.                 LAYOUT_BevelStyle,    BVS_FIELD,
  211.                 LAYOUT_AddChild,      gadgets[GID_12_BU3] =
  212.                                       NewObject(NULL, "button.gadget",
  213.                     // button
  214.                     GA_ID,            GID_12_BU3,
  215.                     GA_RelVerify,     TRUE,
  216.                     GA_Text,          "Pro_cess",
  217.                 TAG_END),
  218.                 CHILD_WeightedWidth,  50,
  219.                 LAYOUT_AddChild,      gadgets[GID_12_BU4] =
  220.                                       NewObject(NULL, "button.gadget",
  221.                     // button
  222.                     GA_ID,            GID_12_BU2,
  223.                     GA_RelVerify,     TRUE,
  224.                     GA_Text,          "Stop",
  225.                     GA_Disabled,      TRUE,
  226.                     TAG_END),
  227.                 CHILD_WeightedWidth,  50,
  228.                 TAG_END),
  229.             CHILD_WeightedHeight,     0,
  230.             LAYOUT_AddChild,          gadgets[GID_12_BU2] =
  231.                                       NewObject(NULL, "button.gadget",
  232.                 // button
  233.                 GA_ID,                GID_12_BU2,
  234.                 GA_RelVerify,         TRUE,
  235.                 GA_Text,              "_Menu",
  236.                 TAG_END),
  237.             CHILD_WeightedHeight,     0,
  238.             TAG_END),
  239.     TAG_END)
  240.     ))
  241.     {   rq("Can't create ReAction objects!");
  242.     }
  243.     unlockscreen();
  244.  
  245.     // Open the window.
  246.  
  247.     if (!(MainWindowPtr = (struct Window *) DoMethod((Object *) object, WM_OPEN, NULL)))
  248.     {   rq("Can't open ReAction window!");        
  249.     }
  250.     app = (1L << AppPort->mp_SigBit);
  251.     // Obtain the window wait signal mask.
  252.     GetAttr(WINDOW_SigMask, object, &signal);
  253.     ActivateLayoutGadget(gadgets[GID_12_LY1], MainWindowPtr, NULL, (Object) gadgets[GID_12_ST1]);
  254.     reaction_loop();
  255.  
  256.     /* Disposing of the window object will also close the window if it is
  257.      * already opened, and it will dispose of the layout object attached to it.
  258.      */
  259.     DisposeObject(object);
  260.     MainWindowPtr = NULL;
  261.     DeleteMsgPort(AppPort);
  262.  
  263.     if (quit)
  264.     {   cleanexit(EXIT_SUCCESS);
  265. }   }
  266.  
  267. AGLOBAL void icon_do(void)
  268. {   STRPTR stringptr;
  269.  
  270.     if (!(GetAttr
  271.     (   CHOOSER_Selected, gadgets[GID_12_CH1], (ULONG *) &(icon.type)
  272.     )))
  273.     {   rq("Unsupported inquiry!"); // should never happen
  274.     }
  275.     if (!(GetAttr
  276.     (   STRINGA_TextVal, gadgets[GID_12_ST1], (ULONG *) &stringptr
  277.     )))
  278.     {   rq("Unsupported inquiry!"); // should never happen
  279.     }
  280.     strcpy(shared.pathname, stringptr);
  281.     // to other similar parts of f12.c
  282.     if (!(GetAttr
  283.     (   GA_Selected, gadgets[GID_12_CB1], (ULONG *) &(icon.optimize)
  284.     )))
  285.     {   rq("Unsupported inquiry!"); // should never happen
  286.     }
  287.     if (!(GetAttr
  288.     (   GA_Selected, gadgets[GID_12_CB2], (ULONG *) &(icon.planar)
  289.     )))
  290.     {   rq("Unsupported inquiry!"); // should never happen
  291.     }
  292.  
  293.     SetGadgetAttrs
  294.     (   gadgets[GID_12_CH1], MainWindowPtr, NULL,
  295.         GA_Disabled, TRUE,
  296.         TAG_END
  297.     );
  298.     SetGadgetAttrs
  299.     (   gadgets[GID_12_CB1], MainWindowPtr, NULL,
  300.         GA_Disabled, TRUE,
  301.         TAG_END
  302.     );
  303.     SetGadgetAttrs
  304.     (   gadgets[GID_12_CB2], MainWindowPtr, NULL,
  305.         GA_Disabled, TRUE,
  306.         TAG_END
  307.     );
  308.     SetGadgetAttrs
  309.     (   gadgets[GID_12_ST1], MainWindowPtr, NULL,
  310.         GA_Disabled, TRUE,
  311.         TAG_END
  312.     );
  313.     SetGadgetAttrs
  314.     (   gadgets[GID_12_BU1], MainWindowPtr, NULL,
  315.         GA_Disabled, TRUE,
  316.         TAG_END
  317.     );
  318.     SetGadgetAttrs
  319.     (   gadgets[GID_12_BU2], MainWindowPtr, NULL,
  320.         GA_Disabled, TRUE,
  321.         TAG_END
  322.     );
  323.     SetGadgetAttrs
  324.     (   gadgets[GID_12_BU3], MainWindowPtr, NULL,
  325.         GA_Disabled, TRUE,
  326.         TAG_END
  327.     );
  328.     SetGadgetAttrs
  329.     (   gadgets[GID_12_BU4], MainWindowPtr, NULL,
  330.         GA_Disabled, FALSE,
  331.         TAG_END
  332.     );
  333.                           
  334.     convert(TRUE);
  335.  
  336.     if (!stop)
  337.     {   SetGadgetAttrs
  338.         (   gadgets[GID_12_ST2], MainWindowPtr, NULL,
  339.             STRINGA_TextVal, "All done.",
  340.             TAG_END
  341.         );
  342.     }
  343.     SetGadgetAttrs
  344.     (   gadgets[GID_12_CH1], MainWindowPtr, NULL,
  345.         GA_Disabled, FALSE,
  346.         TAG_END
  347.     );
  348.     SetGadgetAttrs
  349.     (   gadgets[GID_12_CB1], MainWindowPtr, NULL,
  350.         GA_Disabled, FALSE,
  351.         TAG_END
  352.     );
  353.     SetGadgetAttrs
  354.     (   gadgets[GID_12_CB2], MainWindowPtr, NULL,
  355.         GA_Disabled, FALSE,
  356.         TAG_END
  357.     );
  358.     SetGadgetAttrs
  359.     (   gadgets[GID_12_ST1], MainWindowPtr, NULL,
  360.         GA_Disabled, FALSE,
  361.         TAG_END
  362.     );
  363.     SetGadgetAttrs
  364.     (   gadgets[GID_12_BU1], MainWindowPtr, NULL,
  365.         GA_Disabled, FALSE,
  366.         TAG_END
  367.     );
  368.     SetGadgetAttrs
  369.     (   gadgets[GID_12_BU2], MainWindowPtr, NULL,
  370.         GA_Disabled, FALSE,
  371.         TAG_END
  372.     );
  373.     SetGadgetAttrs
  374.     (   gadgets[GID_12_BU3], MainWindowPtr, NULL,
  375.         GA_Disabled, FALSE,
  376.         TAG_END
  377.     );
  378.     SetGadgetAttrs
  379.     (   gadgets[GID_12_BU4], MainWindowPtr, NULL,
  380.         GA_Disabled, TRUE,
  381.         TAG_END
  382.     );
  383. }
  384.  
  385. AGLOBAL void iconconvert(ABOOL gui)
  386. {   TEXT               saystring[LONGFIELD + 1];
  387.     ULONG              length = strlen(shared.thisfile);
  388.     struct DiskObject* IconPtr;
  389.  
  390.     if (length <= 5) // in case we get passed an empty string
  391.     {   return;
  392.     }
  393.     if (!stricmp(&(shared.thisfile[length - 5]), ".info"))
  394.     {   shared.thisfile[length - 5] = 0;
  395.     }
  396.    
  397.     strcpy(saystring, "Processing ");
  398.     strcat(saystring, shared.thisfile);
  399.     strcat(saystring, ".info...");
  400.     if (gui)
  401.     {   SetGadgetAttrs
  402.         (   gadgets[GID_12_ST2], MainWindowPtr, NULL,
  403.             STRINGA_TextVal, saystring,
  404.             TAG_END
  405.         );
  406.     } else
  407.     {   Printf("%s", saystring);
  408.         Flush(Output());
  409.         saystring[0] = 0;
  410.     }
  411.  
  412.     if (IconPtr = GetIconTags(shared.thisfile, TAG_DONE))
  413.     {   IconPtr->do_Type = (UWORD) icon.type + 1;
  414.         if (PutIconTags(shared.thisfile, IconPtr,
  415.             ICONPUTA_NotifyWorkbench,     TRUE,
  416.             ICONPUTA_DropPlanarIconImage, (BOOL) !icon.planar,
  417.             ICONPUTA_OptimizeImageSpace,  (BOOL) icon.optimize,
  418.             TAG_DONE
  419.         ))
  420.         {   strcat(saystring, "done.");
  421.         } else strcat(saystring, "failed to write!");
  422.     } else strcat(saystring, "failed to read!");
  423.  
  424.     if (gui)
  425.     {   SetGadgetAttrs
  426.         (   gadgets[GID_12_ST2], MainWindowPtr, NULL,
  427.             STRINGA_TextVal, saystring,
  428.             TAG_END
  429.         );
  430.     } else
  431.     {   Printf("%s\n", saystring);
  432.     }
  433.  
  434.     checkabort(gui);
  435. }
  436.  
  437. AGLOBAL void icon_loop(ULONG gid)
  438. {   STRPTR stringptr;
  439.  
  440.     switch (gid)
  441.     {
  442.     case GID_12_CH1:
  443.         if (!(GetAttr
  444.         (   CHOOSER_Selected, gadgets[GID_12_CH1], (ULONG *) &(icon.type)
  445.         )))
  446.         {   rq("Unsupported inquiry!"); // should never happen
  447.         }
  448.     break;
  449.     case GID_12_ST1:
  450.         if (!(GetAttr
  451.         (   STRINGA_TextVal, gadgets[GID_12_ST1], (ULONG *) &stringptr
  452.         )))
  453.         {   rq("Unsupported inquiry!"); // should never happen
  454.         }
  455.     break;
  456.     case GID_12_BU1:
  457.         multiasl("#?.info");
  458.         SetGadgetAttrs
  459.         (   gadgets[GID_12_ST1], MainWindowPtr, NULL,
  460.             STRINGA_TextVal,  shared.pathname,
  461.             TAG_END
  462.         );
  463.     break;
  464.     case GID_12_BU2:
  465.         page = 0;
  466.     break;
  467.     case GID_12_BU3:
  468.         icon_do();
  469.     break;
  470.     case GID_12_CB1:
  471.         if (!(GetAttr
  472.         (   GA_Selected, gadgets[GID_12_CB1], (ULONG *) &(icon.optimize)
  473.         )))
  474.         {   rq("Unsupported inquiry!"); // should never happen
  475.         }
  476.     break;
  477.     case GID_12_CB2:
  478.         if (!(GetAttr
  479.         (   GA_Selected, gadgets[GID_12_CB2], (ULONG *) &(icon.planar)
  480.         )))
  481.         {   rq("Unsupported inquiry!"); // should never happen
  482.         }
  483.     break;
  484.     default:
  485.     break;
  486. }   }
  487.  
  488.